package jdbc;

import socket.DBUtil;

import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;

public class JDBCDemo3 {
    /*public static void main(String[] args) {
        try (Connection conn = DBUtil.getConnection();) {
            Statement statement = conn.createStatement();
            String sql = "UPDATE userinfo \n" +
                    "SET password=348571\n" +
                    "WHERE username='王克晶';";
            int number = statement.executeUpdate(sql);
            if (number > 0) {
                System.out.println("修改成功");
            } else {
                System.out.println("修改不成功");
            }
        } catch (SQLException e) {
            throw new RuntimeException(e);
        }
    }*/
    /*public static void main(String[] args) {
        try (Connection conn = DBUtil.getConnection();) {
            Statement statement = conn.createStatement();
            String sql = "DELETE FROM userinfo WHERE username='刘集';";
            int number = statement.executeUpdate(sql);
            if (number > 0) {
                System.out.println("删除成功");
            } else {
                System.out.println("删除不成功");
            }
        } catch (SQLException e) {
            throw new RuntimeException(e);
        }
    }*/
    public static void main(String[] args) {
        try (Connection conn = DBUtil.getConnection();) {
            Statement statement = conn.createStatement();
            String sql = "SELECT * FROM teacher ;";
            ResultSet resultSet = statement.executeQuery(sql);
            while (resultSet.next()){
                String name = resultSet.getString("name");
                int age = resultSet.getInt("age");
                System.out.println(name + age);
            }
        } catch (SQLException e) {
            throw new RuntimeException(e);
        }
    }
}

